package com.example.recyclerviewlearn;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.SurfaceControl;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import static android.graphics.Bitmap.Config.RGBA_F16;
import static android.graphics.Bitmap.Config.RGB_565;

public class MainActivity_main extends AppCompatActivity {
    private static final String TAG = "MainActivity_main";

    RecyclerView mRecyclerView;

    private Handler mHandler = new Handler();

    private int mCount = 0;

    private Runnable mRunnable = new Runnable() {
        @Override
        public void run() {
            Log.i(TAG, "run: handler runnable " + mCount);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
                WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
        setContentView(R.layout.activity_main_main);
        mRecyclerView = findViewById(R.id.recyclerView);
        MyAdapter myAdapter = new MyAdapter(getApplicationContext(), initData());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
        mRecyclerView.setLayoutManager(linearLayoutManager);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mRecyclerView.setAdapter(myAdapter);

        // 判断view是否使用硬件加速应该在view已经添加到界面上的时候去进行判断，而不应该在一开始就进行盘面段
        mRecyclerView.post(new Runnable() {
            @Override
            public void run() {
                Log.i(TAG, "onCreate: mRecyclerView" + mRecyclerView.isHardwareAccelerated());
            }
        });
    }

    //初始化数据
    private List<String> initData() {
        int size = 60;
        List<String> myData = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            myData.add("str: " + i);
        }
        return myData;
    }
}